#encoding=utf-8
#!/usr/bin/python

import cgi
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template


class MainPage(webapp.RequestHandler):
  
  def get(self):
    page_str = ''
    page_str += """
      <html>
        <body>
          <form action="/demo/sign" method="post">
            <div><textarea name="content" rows="3" cols="60"></textarea></div>
            <div><input type="submit" value="Sign Guestbook"></div>
          </form>
        </body>
      </html>"""
    self.response.out.write(page_str)

  def post(self):
    page_str = ''
    page_str += '<html><body>is post You wrote:<pre>'
    page_str += cgi.escape(self.request.get('content'))
    page_str += '</pre></body></html>'
    self.response.out.write(page_str)

class Guestbook(webapp.RequestHandler):
  def post(self):
    page_str = ''
    page_str += '<pre>post to get </pre>'
    self.response.out.write(page_str)
    self.get()

  def get(self):
    page_str = ''
    page_str += '<html><body>get You wrote:<pre>'
    page_str += cgi.escape(self.request.get('demo'))
    page_str += cgi.escape(self.request.get('url'))
    page_str += '</pre></body></html>'


    self.response.out.write(page_str)

def main():
  application = webapp.WSGIApplication(
                                       [('/demo', MainPage),
                                        ('/demo/.*', Guestbook)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__" :
  main()  